<?php

class RunTimeWorkflowSynchronizationNode extends AbstractRunTimeWorkflowMergeNode
{

  protected function doDeliver ()
  {
    $key = sprintf('%s_num_calls_deliver', $this->getIdentifier());
    $container = $this->workflow->getContainer();
    $num_calls = $container->getValue($key, 0);
    $num_calls ++;
    $container->setValue($key, $num_calls);
    $this->workflow->handleContainerUpdated();
    
    if ($num_calls == $this->getNumInNodes())
    {
      $this->workflow->handleWorkItemDelivered($this);
      $this->complete();
    }
  }

  protected function doExecute ($action = null)
  {
    throw new Exception();
  }

  protected function doComplete ()
  {
    $this->workflow->handleWorkItemCompleted($this);
    $this->deliverFirstOutNode();
  }

  public function getNumInNodes ()
  {
    return $this->design_time_node->getMinInNodes();
  }
}